package cn.tedu.luban.order.main.consumer;

import cn.tedu.luban.order.main.service.OrderService;
import com.tedu.inn.protocol.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 让底层消费者监听order_delay_topic 拿到消息 交给当前消费类处理
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "order_delay_topic",consumerGroup = "delay_consumer")
public class OrderDelayConsumer implements RocketMQListener<String> {
    @Autowired
    private OrderService orderService;

    /**
     * 保证消费业务方法 满足
     * 1. 幂等的 重复消费同一个订单编号的延迟逻辑 结果相同
     * 2. 保证线程并发冲突的问题,可以添加分布式锁可能和 签到有冲突
     * 签到 是从10--20
     * 延迟 是从10--(-30)
     * 经过分析,不需要添加分布式锁,并发不高,底层sql是乐观锁 status=#{查到的status}
     * @param orderNo
     */
    @Override
    public void onMessage(String orderNo) {
        try {
            orderService.orderDelay(orderNo);
        }catch (BusinessException e){
            log.error("消费延迟出现异常记录日志:",e);
        }
    }
}
